@extends('Admin.layout.layout')
@section('title','商品列表')
@section('content')
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">商品列表</h1>
		</div>
		<!-- /.col-lg-12 -->
	</div>
	<div class="row">
	    <div class="col-lg-12">
	        <div class="panel panel-default">
	            <div class="panel-heading">
	                商品列表
	            </div>
	            <!-- /.panel-heading -->
	            <div class="panel-body">
	                <div class="dataTable_wrapper">
	                    <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
	                   	 <form action="{{url('admin/remen/index')}}" method="get">
	                   	 <div class="row">
	                   		 <div class="col-sm-6">
	                   			 <div class="dataTables_length" id="dataTables-example_length">
				                    <label>显示
				                    <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
					                    <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
					                    <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
					                    <option value="50" @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
					                    <option value="100" @if(!empty($request['num']) && $request['num'] == 100) { selected } @endif>100</option>
				                    </select>条
				                    </label>
				                 </div>
				             </div>
				         <div class="col-sm-6">
				         	<div id="dataTables-example_filter" class="dataTables_filter">
					         	<label>
					         		商品名称:<input class="form-control input-sm" placeholder="" aria-controls="dataTables-example" type="text" name="search">
					         		<button type="submit" class="btn btn-info" style="margin-left:5px;">搜索</button>
					         	</label>
				         	</div>
				         </div>
				         	</div>
				         	</form>
				        <div class="row">
				        	<div class="col-sm-12">
				         		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
		                        	<thead>
			                            <tr role="row">
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 202px;" aria-label="Browser: activate to sort column ascending">商品ID</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 184px;" aria-label="Platform(s): activate to sort column ascending">商品名称</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 151px;" aria-label="Engine version: activate to sort column ascending">商品分类</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 120px;" aria-label="Engine version: activate to sort column ascending">商品价格</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 120px;" aria-label="Engine version: activate to sort column ascending">商品库存</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 151px;" aria-label="Engine version: activate to sort column ascending">商品状态</th>
				                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 160px;" aria-label="CSS grade: activate to sort column ascending">操作</th>
			                            </tr>
		                       		</thead>
	                        	<tbody>
	                        @foreach($goods as $k=>$v)
	                            <tr class="gradeA odd" role="row">
                                    <td class="gid">{{$v->id}}</td>
                                    <td>{{$v->goods_name}}</td>
                                    <td>{{$v->name}}</td>
                                    <td class="center">{{$v->price}}</td>
                                    <td class="center">{{$v->store}}</td>
                                    <td class="center">{{str_replace([1,2],['上架','下架'],$v->status)}}</td>
                                    <td class="center"><a href="" class="fa fa-trash-o delete" >删除</a> | <a href="{{url('admin/goods/update',['id'=>$v->id])}}" class="fa fa-wrench update">修改</a></td>
                                </tr>
	                        @endforeach
	                        </tbody>
	                    </table></div></div>
						<div class="col-lg-offset-4">
							
	                    	{!! $goods->appends($request)->render() !!}
						</div>	
	                </div>
	                <!-- /.table-responsive -->
	            </div>
	            <!-- /.panel-body -->
	        </div>
	        <!-- /.panel -->
	    </div>
	    <!-- /.col-lg-12 -->
	</div>
@endsection

@section('myjs')
<script type="text/javascript">
	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
	});
	//绑定删除单击事件
	$('.delete').click(function(){
		// alert('删除');
		var id = $(this).parents('tr').find('.gid').html();
		// alert(id);
		//定义当前对象
		var dd = $(this);
		//发送ajax
		$.post('/admin/goods/delete',{id:id},function(data){
			// console.log(data);
			if(data == 1){
				dd.parents('tr').remove();
			}else{
				alert('删除失败');
			}
		});
		return false;
	});
</script>
@endsection